package com.qzsf.backend.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qzsf.backend.common.Result;
import com.qzsf.backend.entity.EventType;
import com.qzsf.backend.mapper.EventTypeMapper;
import com.qzsf.backend.service.EventTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/*
 * @Author: Dennis Chen
 * @CreateTime: 2024/10/31 10:12 周四
 * @Email 1429278462@qq.com
 * @Remark 活动分类服务层实现类
 * @Version 1.0
 */
@Service
public class EventTypeServiceImpl implements EventTypeService {
    @Autowired
    private EventTypeMapper eventTypeMapper;
    @Override
    public Result getAllEventTypes(String type,int pageNo,int pageSize) {
        PageHelper.startPage(pageNo, pageSize);
        if(type == null){
            return Result.success(new PageInfo<>(eventTypeMapper.getAllEventTypes()));
        }else{
            return Result.success(new PageInfo<>(eventTypeMapper.getEventByName(type)));
        }

    }

    @Override
    public Result createEventType(EventType eventType) {
        if(eventTypeMapper.createEventType(eventType)>0){
            return Result.success();
        }else{
            return Result.error("创建活动类型失败");
        }
    }

    @Override
    public Result updateEventType(EventType eventType) {
        if(eventTypeMapper.updateEventType(eventType)>0){
            return Result.success();
        }else{
            return Result.error("更新活动类型失败");
        }
    }

    @Override
    public Result deleteEventType(int id) {
        if(eventTypeMapper.deleteEventType(id)>0){
            return Result.success();
        }else{
            return Result.error("删除活动类型失败");
        }
    }

    @Override
    public Result getEventTypeById(int id) {
        return Result.success(eventTypeMapper.getEventTypeById(id));
    }
}
